﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using LinQ_DTO;

namespace BUS
{
    public class SanPhamBUS
    {

        public List<shop_sanpham> LayTatCaSanPham()
        {

            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.GetAllProduct();
            // return new List<shop_sanpham>();
        }

        public List<shop_sanpham> LaySPTheoLoai(int MaLoaiSP)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamTheoLoai(MaLoaiSP);
        }


        public List<shop_sanpham> LaySanPhamTheoMa(int MaSP)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamTheoMa(MaSP);
        }

        public void ThemSanPham(shop_sanpham a)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            SpDao.ThemSanPham(a);


        }

        public void XoaSanPhamTheoMa(int MaSP)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            SpDao.XoaSanPhamTheoMa(MaSP);



        }

        public void CapNhatSP(shop_sanpham Sp)
        {

            SanPhamDAO SpDao = new SanPhamDAO();
            SpDao.CapNhatSP(Sp);


        }



        
        

///////////////////////////////CODE by nmcuong/////////////////////////

      
        public List<shop_sanpham> GetAllProduct()
        {

            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.GetAllProduct();
           // return new List<shop_sanpham>();
        }

      

       
        
        public List<shop_sanpham> LaySanPhamHotTheoPhai(bool Phai)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamHotTheoPhai(Phai);
        }

        public List<shop_sanpham> LaySanPhamHot()
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamHot();
        }

        public List<shop_sanpham> LaySanPhamHotTheoLoaiPhai(bool Phai, int MaLoai)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            if (MaLoai == 0)
                return SpDao.LaySanPhamHotTheoPhai(Phai);
            return SpDao.LaySanPhamHotTheoLoaiPhai(Phai,MaLoai);
        }


        public List<shop_sanpham> LaySanPhamKhuyenMaiTheoPhai(bool Phai)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamKhuyenMaiTheoPhai(Phai);
        }

        public List<shop_sanpham> LaySanPhamKhuyenMaiTheoLoaiPhai(bool Phai, int MaLoai)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamKhuyenMaiTheoLoaiPhai(Phai,MaLoai);
        }



        public List<shop_sanpham> LaySanPhamKhuyenMai()
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamKhuyenMai();
        }




        public List<shop_sanpham> LaySanPhamTheoPhai(bool Phai)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamTheoPhai(Phai);
        }

        public List<shop_sanpham> LaySanPhamTheoLoaiPhai(bool Phai, int MaLoai)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamTheoLoaiPhai(Phai,MaLoai);
        }

        public void CapNhatDiem(shop_sanpham Sp)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            SpDao.CapNhatDiem(Sp);
        }

        public int LayDiemCuaSanPham(shop_sanpham Sp)
        {
            int Diem = 0;
            foreach (shop_chamdiem Cd in Sp.shop_chamdiems)
                if (Cd.MaSanPham == Sp.MaSanPham)
                    Diem += (int)Cd.Diem;

            return Diem;
        }

        public void ThemDiemChoSanPham(shop_chamdiem NewRecord)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            SpDao.ThemDiemChoSanPham(NewRecord);
        }

        public List<shop_sanpham> TimSanPhamTheoTen(string TenSp)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.TimSanPhamTheoTen(TenSp);
        }

        public List<shop_sanpham> TimSanPhamTheoLoaiGiaNhaSX(decimal LowestCost, decimal HighestCost, int MaLoai, int MaNSX)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.TimSanPhamTheoLoaiGiaNhaSX(LowestCost,HighestCost,MaLoai,MaNSX);
        }

        /************************************************************************************************************        *                          coder: TRAN KINH LY 
         ***********************************************************************************************************/
        public List<shop_sanpham> LaySanPhamGioiHan(int iStart, int iLimit)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamGioiHan(iStart, iLimit);
        }

        public int LaySoLuongSanPham()
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySoLuongSanPham();
        }

        public List<shop_sanpham> LaySanPhamTheoKhoa(String key_search)
        {
            SanPhamDAO SpDao = new SanPhamDAO();
            return SpDao.LaySanPhamTheoKhoa(key_search);
        }
        /************************************************************************************************************        *                          coder: TRAN KINH LY 
         ***********************************************************************************************************/


    }
}
